home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
asynchat.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
6KB
|
216 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import socket
import asyncore
from collections import deque
class async_chat(asyncore.dispatcher):
ac_in_buffer_size = 4096
ac_out_buffer_size = 4096
def __init__(self, conn = None):
self.ac_in_buffer = ''
self.ac_out_buffer = ''
self.producer_fifo = fifo()
asyncore.dispatcher.__init__(self, conn)
def collect_incoming_data(self, data):
raise NotImplementedError, 'must be implemented in subclass'
def found_terminator(self):
raise NotImplementedError, 'must be implemented in subclass'
def set_terminator(self, term):
self.terminator = term
def get_terminator(self):
return self.terminator
def handle_read(self):
try:
data = self.recv(self.ac_in_buffer_size)
except socket.error:
why = None
self.handle_error()
return None
self.ac_in_buffer = self.ac_in_buffer + data
while self.ac_in_buffer:
lb = len(self.ac_in_buffer)
terminator = self.get_terminator()
None if not terminator else lb < n
terminator_len = len(terminator)
index = self.ac_in_buffer.find(terminator)
if index != -1:
if index > 0:
self.collect_incoming_data(self.ac_in_buffer[:index])
self.ac_in_buffer = self.ac_in_buffer[index + terminator_len:]
self.found_terminator()
continue
index = find_prefix_at_end(self.ac_in_buffer, terminator)
if index:
if index != lb:
self.collect_incoming_data(self.ac_in_buffer[:-index])
self.ac_in_buffer = self.ac_in_buffer[-index:]
break
continue
self.collect_incoming_data(self.ac_in_buffer)
self.ac_in_buffer = ''
def handle_write(self):
self.initiate_send()
def handle_close(self):
self.close()
def push(self, data):
self.producer_fifo.push(simple_producer(data))
self.initiate_send()
def push_with_producer(self, producer):
self.producer_fifo.push(producer)
self.initiate_send()
def readable(self):
return len(self.ac_in_buffer) <= self.ac_in_buffer_size
def writable(self):
if self.ac_out_buffer == '' and self.producer_fifo.is_empty():
pass
return not (self.connected)
def close_when_done(self):
self.producer_fifo.push(None)
def refill_buffer(self):
while len(self.producer_fifo):
p = self.producer_fifo.first()
if p is None:
if not self.ac_out_buffer:
self.producer_fifo.pop()
self.close()
return None
elif isinstance(p, str):
self.producer_fifo.pop()
self.ac_out_buffer = self.ac_out_buffer + p
return None
data = p.more()
if data:
self.ac_out_buffer = self.ac_out_buffer + data
return None
else:
self.producer_fifo.pop()
data
return None
continue
return None
def initiate_send(self):
obs = self.ac_out_buffer_size
if len(self.ac_out_buffer) < obs:
self.refill_buffer()
if self.ac_out_buffer and self.connected:
try:
num_sent = self.send(self.ac_out_buffer[:obs])
if num_sent:
self.ac_out_buffer = self.ac_out_buffer[num_sent:]
except socket.error:
why = None
self.handle_error()
return None
except:
None<EXCEPTION MATCH>socket.error
None<EXCEPTION MATCH>socket.error
def discard_buffers(self):
self.ac_in_buffer = ''
self.ac_out_buffer = ''
while self.producer_fifo:
self.producer_fifo.pop()
class simple_producer:
def __init__(self, data, buffer_size = 512):
self.data = data
self.buffer_size = buffer_size
def more(self):
if len(self.data) > self.buffer_size:
result = self.data[:self.buffer_size]
self.data = self.data[self.buffer_size:]
return result
else:
result = self.data
self.data = ''
return result
class fifo:
def __init__(self, list = None):
if not list:
self.list = deque()
else:
self.list = deque(list)
def __len__(self):
return len(self.list)
def is_empty(self):
return not (self.list)
def first(self):
return self.list[0]
def push(self, data):
self.list.append(data)
def pop(self):
if self.list:
return (1, self.list.popleft())
else:
return (0, None)
def find_prefix_at_end(haystack, needle):
l = len(needle) - 1
while l and not haystack.endswith(needle[:l]):
l -= 1
return l